<?php
	session_start();
	require 'database/profile_handler.php';
	require 'database/photo_handler.php';
    require 'database/photo_uploader.php';
	require 'database/follower_handler.php';
    require_once 'database/notif_handler.php';
	
	if (isset($_GET['photo_id']))
		$photo_id = $_GET['photo_id'];
	if (isset($_GET['usr_tag']))
		$usr_tag = $_GET['usr_tag'];
	
	$u = $_SESSION['Username'];	
	if (isset($_GET['UserTujuan']) && $_GET['UserTujuan']!="undefined") {
		$u = $_GET['UserTujuan'];
		if (isset($_SESSION['Username'])) {
			$user_view = $_SESSION['Username'];
			$pf = new profile_handler();
			$pf->retr_details($user_view,5);
			$ph = new photo_handler();
			$ph->get_url($pf->result[3][0]);
			$prof_pic_user_view = $ph->result[0];
		}
	}
	if (isset($_SESSION['Username'])) {		
		$pf = new profile_handler();
		$pf->retr_details($u,5);
		$nama_user = $pf->result[4];
		$ph = new photo_handler();
		$ph->get_url($pf->result[3][0]);
		$prof_pic_user = $ph->result[0];
	}
	if (isset($_GET['delete_comment']) && $_GET['delete_comment']==1) {
		$delphoto_handler = new photo_handler();
		$delphoto_handler->del_comment($_GET['photo_comment_id']);
		$usrphoto_handler = new photo_handler();
		$usrphoto_handler->view_photo($photo_id);
		if (count($usrphoto_handler->result[3])<7) {
			?><?php
		} else {
			?><a id="link_name" href="javascript:viewLessComment('<?php echo $photo_id;?>');">View Less Comments</a><?php
		}
	} else if (isset($_GET['comment'])) {
			$submit_comment_photo = new photo_handler();
			$submit_comment_photo->add_comment($photo_id,$_SESSION['Username'],$_GET['comment']);			
			$usrphoto_handler = new photo_handler();
			$usrphoto_handler->view_photo($photo_id);
			if ($usrphoto_handler->result[3][0]!=NULL) {
				for ($k=count($usrphoto_handler->result[3])-1;$k<count($usrphoto_handler->result[3]);$k++) {
					$commentator_details = new profile_handler();
					$commentator_details->retr_details($usrphoto_handler->result[3][$k],5);
					$commentator_photo = new photo_handler();
					$commentator_photo->get_url($commentator_details->result[3][0]);
					?>
					<div id="photo_comment_content<?php echo $usrphoto_handler->result[5][$k];?>">
					<?php 
					$valid = false;
					if ($_SESSION['Username']==$usrphoto_handler->result[3][$k] || $_SESSION['Username']==$usrphoto_handler->result[1])
						$valid = true;
					if ($valid)
					{
						?>
					<div id="commentphoto_delete"><a href="javascript:deleteComment('<?php echo $usrphoto_handler->result[5][$k];?>','<?php echo $photo_id;?>');">x</a></div>
					<?php
					}
					?>
					<img id="image_commentator_photo" src="<?php echo $commentator_photo->result[0]; ?>" alt="" />
					<div id="name_commentator_photo"><a id="link_name" href="otherprofile.php?id=<?php echo $usrphoto_handler->result[3][$k]; ?>">
					<?php
						echo $commentator_details->result[4][0];
					?>
					</a>
					</div>
					<div id="commentphoto_content">
					<?php
					// echo comment body
					echo $usrphoto_handler->result[4][$k];
					?>
					</div>
					</div>
					<?php
				}
			}
	} else if (isset($_GET['viewAllComment']) && $_GET['viewAllComment']==1) {
		$usrphoto_handler = new photo_handler();
        $usrphoto_handler->view_photo($_GET['photo_id']);
		$mulai_tampil = 0;
		?>
		<div id="less_comment_photo"><a id="link_name" href="javascript:viewLessComment('<?php echo $photo_id;?>');">View Less Comments</a></div>
        /*tagtag*/
		<?php
		for ($k=$mulai_tampil;$k<count($usrphoto_handler->result[3]);$k++) {
			$commentator_details = new profile_handler();
			$commentator_details->retr_details($usrphoto_handler->result[3][$k],5);
			$commentator_photo = new photo_handler();
			$commentator_photo->get_url($commentator_details->result[3][0]);
			?>
			<div id="photo_comment_content<?php echo $usrphoto_handler->result[5][$k];?>">
			<?php 
			$valid = false;
			if ($_SESSION['Username']==$usrphoto_handler->result[3][$k] || $_SESSION['Username']==$usrphoto_handler->result[1])  
				$valid = true;
			if ($valid)
			{
				?>
			<div id="commentphoto_delete"><a href="javascript:deleteComment('<?php echo $usrphoto_handler->result[5][$k];?>','<?php echo $photo_id;?>');">x</a></div>
			<?php
			}
			?>
			<img id="image_commentator_photo" src="<?php echo $commentator_photo->result[0]; ?>" alt="" />
			<div id="name_commentator_photo"><a id="link_name" href="otherprofile.php?id=<?php echo $usrphoto_handler->result[3][$k]; ?>">
			<?php
				echo $commentator_details->result[4][0];
			?>
			</a>
			</div>
			<div id="commentphoto_content">
			<?php
			// echo comment body
			echo $usrphoto_handler->result[4][$k];
			?>
			</div>
			</div>
			<?php
		}
	} else if (isset($_GET['viewLessComment']) && $_GET['viewLessComment']==1) {
		$usrphoto_handler = new photo_handler();
        $usrphoto_handler->view_photo($_GET['photo_id']);
		if (count($usrphoto_handler->result[3])<7)
			$mulai_tampil = 0;
		else {
			$mulai_tampil = count($usrphoto_handler->result[3])-2;
			}
		?>
		<div id="less_comment_photo"><a id="link_name" href="javascript:viewAllComment('<?php echo $photo_id;?>');">View All Comments(<?php echo $mulai_tampil;?>)</a></div>
        /*tagtag*/
		<?php
		for ($k=$mulai_tampil;$k<count($usrphoto_handler->result[3]);$k++) {
			$commentator_details = new profile_handler();
			$commentator_details->retr_details($usrphoto_handler->result[3][$k],5);
			$commentator_photo = new photo_handler();
			$commentator_photo->get_url($commentator_details->result[3][0]);
			?>
			<div id="photo_comment_content<?php echo $usrphoto_handler->result[5][$k];?>">
			<?php 
			$valid = false;
			if ($_SESSION['Username']==$usrphoto_handler->result[3][$k] || $_SESSION['Username']==$usrphoto_handler->result[1])  
				$valid = true;
			if ($valid)
			{
				?>
			<div id="commentphoto_delete"><a href="javascript:deleteComment('<?php echo $usrphoto_handler->result[5][$k];?>');">x</a></div>
			<?php
			}
			?>
			<img id="image_commentator_photo" src="<?php echo $commentator_photo->result[0]; ?>" alt="" />
			<div id="name_commentator_photo"><a id="link_name" href="otherprofile.php?id=<?php echo $usrphoto_handler->result[3][$k]; ?>">
			<?php
				echo $commentator_details->result[4][0];
			?>
			</a>
			</div>
			<div id="commentphoto_content">
			<?php
			// echo comment body
			echo $usrphoto_handler->result[4][$k];
			?>
			</div>
			</div>
			<?php
		}
	} else if (isset($_GET['arrow_click']) && $_GET['arrow_click']==1) {
		// view one image large + arrow next&prev, comment, edit, rating
		 $usrphoto_handler = new photo_handler();
		 $usrphoto_handler->get_url($photo_id);
		 $usrphoto_url = $usrphoto_handler->result[0];
			$usrphoto_handler = new photo_handler();
			if ($usr_tag==null) {
				if ($user_view==null && isset($_SESSION['Username'])) {
					$usrphoto_handler->view_all_user_photos($u);
				} else {
					// cari hubungan antara $user_view(yang lagi liatt) dengan $u (yang fotonya diliat)
					$temp_phandler = new follower_handler();
					if ($_SESSION['Username']==null) {
						$hubungan = "everyone";
					} else if ($temp_phandler->is_follow($user_view,$u)) {
						$hubungan = "just followers";
					} else {
						$hubungan = "members only";	
					}
					$usrphoto_handler->view_user_photos_category($u,$hubungan);
				}
			} else {
				// view tagged photos
				if ($user_view==null && isset($_SESSION['Username'])) {
					$usrphoto_handler->retr_tagged_photo($usr_tag);
				} else {
					// user lain yang liat
					if (isset($_SESSION['Username'])) {
						// member
						$usrphoto_handler->view_usertag_photos_category($usr_tag,$user_view);
					} else {
						// bukan member
						$usrphoto_handler->view_usertag_photos_category($usr_tag,"everyone");
					}
				}
			}
			if ($usrphoto_handler->result[0][0]!=NULL) {
				for ($kk=0;$kk<count($usrphoto_handler->result[0]);$kk++) {
					if ($usrphoto_handler->result[0][$kk]==$photo_id) {
						if($kk==0) {
							$prev_photo = null;
						} else {
							$prev_photo = $kk;
						}
						if ($kk==count($usrphoto_handler->result[0])-1) {
							$next_photo = null;
						} else {
							$next_photo = $kk+1;
						}
						break;
					}
				}
				if ($prev_photo!=null) {
					if ($usr_tag==null) {
						if ($user_view==null && isset($_SESSION['Username'])) {
							?>
							<div id="arrow_left"><a href="javascript:arrow_click('<?php echo $usrphoto_handler->result[0][$prev_photo-1];?>');" alt=""><</a></div> 
							<?php
						} else {
							?>
							<div id="arrow_left"><a href="homepage.php?view=2&photo_id=<?php echo $usrphoto_handler->result[0][$prev_photo-1];?>&UserTujuan=<?php echo $u;?>" alt=""><</a></div> 
							<?php
						}
					} else {
						if ($user_view==null && isset($_SESSION['Username'])) {
							?>
							<div id="arrow_left"><a href="homepage.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrphoto_handler->result[0][$prev_photo-1];?>" alt=""><</a></div> 
							<?php
                            } else {
                            ?>
                            <div id="arrow_left"><a href="homepage.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrphoto_handler->result[0][$prev_photo-1];?>&UserTujuan=<?php echo $u;?>" alt=""><</a></div> 
							<?php
						}
					}
				}
				?>
				<div id="center_image">
				<a href="<?php echo $usrphoto_url; ?>" ><img class="preview_gedhe" src="<?php echo $usrphoto_url; ?>" alt="description" /></a>
				</div>
				<?php
				if ($next_photo!=null) {
					if ($usr_tag==null) {
						if ($user_view==null && isset($_SESSION['Username'])) {
							?>
							<div id="arrow_right"><a href="javascript:arrow_click('<?php echo $usrphoto_handler->result[0][$next_photo];?>');" alt="">></a></div>
							<?php
							}else {
							?>
							<div id="arrow_right"><a href="javascript:arrow_click('<?php echo $usrphoto_handler->result[0][$next_photo];?>','<?php echo $u;?>');" alt="">></a></div>
							<?php									
						}
					} else {
						if ($user_view==null && isset($_SESSION['Username'])) {
							?>
							<div id="arrow_right"><a href="gallery.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrphoto_handler->result[0][$next_photo];?>" alt="">></a></div>               
							<?php
						}else {
							?>
							<div id="arrow_right"><a href="gallery.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrphoto_handler->result[0][$next_photo];?>&UserTujuan=<?php echo $u;?>" alt="">></a></div>               
							<?php	
						}
					}
				}
			}
			
			?>/*tagtag*/<?php
			$rating_handler = new photo_handler();
			$rating_handler->retr_photo_rating($photo_id);
			$cekrating_handler = new photo_handler();
			$cekrating_handler->retr_photo_owner($photo_id);
			if (isset($_SESSION['Username']) && $cekrating_handler->result[0]!=$_SESSION['Username']) {
			//if ($_SESSION['Username']!=null) {
				echo "<a id=\"link_name\" href=\"javascript:decreaseRating('".$photo_id."');\">-</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
			?><span id="rating_text"><?php
			echo $rating_handler->result[0];
			?></span><?php
			if (isset($_SESSION['Username']) && $cekrating_handler->result[0]!=$_SESSION['Username']) {
			//if ($_SESSION['Username']!=null) {
				echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id=\"link_name\" href=\"javascript:increaseRating('".$photo_id."');\">+</a>";
			}
			// indeks tag 2
			?>/*tagtag*/<?php
			$deskripsi_photo = new photo_handler();
			$deskripsi_photo->retr_photo_details($photo_id,8);
			$prof_temp = new profile_handler();
			$prof_temp->get_nama_lengkap($deskripsi_photo->result[8][0]);								
			?>
			<a id="link_name" href="otherprofile.php?UserTujuan=<?php echo $deskripsi_photo->result[8][0];?>" alt="">
			<?php
				echo $prof_temp->result[0];
			?>
			</a>
            /*tagtag*/
			<?php
			// indeks tag 3
				if ($deskripsi_photo->result[0][0]!=null)
					echo $deskripsi_photo->result[0][0];
				else echo " ";
			?>
			/*tagtag*/
			<?php
			// indeks tag 4
				if ($deskripsi_photo->result[1][0]!=null)
					echo $deskripsi_photo->result[1][0];
				else echo " ";
			?>
			/*tagtag*/
			<?php
			// indeks tag 5
				if ($deskripsi_photo->result[2][0]!=null)
					echo $deskripsi_photo->result[2][0];
				else echo " ";
			?>
			/*tagtag*/
			<?php
			// indeks tag 6
				if ($deskripsi_photo->result[3][0]!=null)
					echo $deskripsi_photo->result[3][0];
				else echo " ";
			?>
			/*tagtag*/
			<?php
			// indeks tag 7
				if ($deskripsi_photo->result[4][0]!=null)
					echo $deskripsi_photo->result[4][0];
				else echo " ";
			?>
			/*tagtag*/
			<?php
			// indeks tag 8
				if ($deskripsi_photo->result[5][0]!=null)
					echo $deskripsi_photo->result[5][0];
				else echo " ";
			?>
			/*tagtag*/
			<?php
			// indeks tag 9
				if ($deskripsi_photo->result[6][0]!=null) {
					if ($deskripsi_photo->result[6][0]==1)
						echo "Yes";
					else
						echo "No";
				} else
					echo " ";
			?>
            /*tagtag*/
            <?php
			// indeks tag 10 middle coloumn
			?>
			<div class="group_content" id="tag_place">
			<span id="_title2">Tag :</span>
			<?php
				$tag_handler = new photo_handler();
				$tag_handler->retr_photo_tag($photo_id);
				$tag_result="";
				if ($tag_handler->result[0] != null) {
					?>
					<div id="tag_content">
						<span id="tag_isi">                            
					<?php
					for ($ll=0;$ll<count($tag_handler->result)-1;$ll++) {
						$tag_profil = new profile_handler();
						$tag_profil->get_nama_lengkap($tag_handler->result[$ll]);
						$tag_result .= "<a id=\"link_name\" href=\"otherprofile.php?UserTujuan=".$tag_handler->result[$ll]."\">".$tag_profil->result[0]."</a>, ";
					}
					$tag_profil = new profile_handler();
					$tag_profil->get_nama_lengkap($tag_handler->result[$ll]);
					$tag_result .= "<a id=\"link_name\" href=\"otherprofile.php?UserTujuan=".$tag_handler->result[$ll]."\">".$tag_profil->result[0]."</a>";
					echo $tag_result;
					?>
						</span>
					</div>
					<?php																																															
				}
				?>
		 </div>                                             
		<div class="group_content" id="photo_comment">
		<?php
		$usrphoto_handler = new photo_handler();
		$usrphoto_handler->view_photo($photo_id);
		if (count($usrphoto_handler->result[3])<7)
				$mulai_tampil = 0;
		else {
			$mulai_tampil = count($usrphoto_handler->result[3])-2;
			?>
			<div id="less_comment_photo"><a id="link_name" href="javascript:viewAllComment('<?php echo $photo_id;?>');">View All Comments(<?php echo $mulai_tampil;?>)</a></div>
			<?php
		}
			?>
			<div id="comment_content_photo">
			<?php
		if ($usrphoto_handler->result[3][0]!=NULL) { 
			for ($k=$mulai_tampil;$k<count($usrphoto_handler->result[3]);$k++) {
				$commentator_details = new profile_handler();
				$commentator_details->retr_details($usrphoto_handler->result[3][$k],5);
				$commentator_photo = new photo_handler();
				$commentator_photo->get_url($commentator_details->result[3][0]);
				?>
				<div id="photo_comment_content<?php echo $usrphoto_handler->result[5][$k];?>">
				<?php 
				$valid = false;
				if ($_SESSION['Username']==$usrphoto_handler->result[3][$k] || $_SESSION['Username']==$usrphoto_handler->result[1])  
					$valid = true;
				if ($valid)
				{
					?>
				<div id="commentphoto_delete"><a href="javascript:deleteComment('<?php echo $usrphoto_handler->result[5][$k];?>','<?php echo $photo_id;?>');">x</a></div>
				<?php
				}
				?>
				<img id="image_commentator_photo" src="<?php echo $commentator_photo->result[0]; ?>" alt="" />
				<div id="name_commentator_photo"><a id="link_name" href="otherprofile.php?id=<?php echo $usrphoto_handler->result[3][$k]; ?>">
				<?php
					echo $commentator_details->result[4][0];
				?>
				</a>
				</div>
				<div id="commentphoto_content">
				<?php
				// echo comment body
				echo $usrphoto_handler->result[4][$k];
				?>
				</div>
				</div>
				<?php
			}
		}
		?>
		</div>
		<?php
		$comment_handler = new photo_handler();
		$comment_handler->retr_photo_details($photo_id,7);
		if ($usr_tag!=null && $comment_handler->result[0]==0) {
			$noshow_comment = false;
		} else if ($user_view!=null && $comment_handler->result[0]==0) {
			$noshow_comment = false;
		} else if (isset($_SESSION['Username']))
			$noshow_comment = true;
		if ($noshow_comment) {
		?>                
		<div id="insert_comment_photo">
			<?php
			if ($user_view==null) {
			?>
			<img id="profpic_small" src="<? echo $prof_pic_user;?>" alt="" style="float:left;" />
			<?php
			} else {
			?>		
			<img id="profpic_small" src="<? echo $prof_pic_user_view;?>" alt="" style="float:left;" />
			<?php
			}
				?>
				<form method="post" action="javascript:submitComment('<?php echo $photo_id;?>', text_comment_photo.value);">
				<div id="insert_comment2">
					<textarea class="textarea" id="text_comment_photo" name="text_comment_photo" size="50px" rows="2" onFocus="if (this.value=='Add a comment') { this.value = '';}" onBlur="if (this.value=='') { this.value = 'Add a comment';}" >Add a comment</textarea>
					<input type="submit" name="SubmitComment" id="SubmitComment2" value="Submit"/>
				</div>
			</form>
		</div>
        /*tagtag*/
		<?php
        // indeks tag 11 right coloumn
		if ($usr_tag==null) {
			?>
            <span id="_title2"><a href="homepage.php?edit=1&photo_id=<?php echo $photo_id;?>" id="link_name" style="font-size:12px;">Edit details this photo</a></span>
            <br />
            <span id="_title2"><a href="javascript:removePhoto('<?php echo $photo_id;?>');" id="link_name" style="font-size:12px;">Remove this photo</a></span>
            <br/>
            <span id="_title2"><a href="javascript:makeprofpic('<?php echo $photo_id;?>');" id="link_name" style="font-size:12px;">Make this my profile picture</a></span>
            <?php 
			}
		}
	} else if (isset($_GET['increaserating'])) {
		$rating = new photo_handler();
		echo $rating->increase_rating($photo_id);	
	} else if (isset($_GET['decreaserating'])) {
		$rating = new photo_handler();
		echo $rating->decrease_rating($photo_id);	
	} else 	if (isset($_GET['remove']) && $_GET['remove']==1 && isset($_GET['photo_id'])) {
		$del_photo = new photo_handler();
		// tambahin javascript untuk memastikan foto akan didelete
		$del_photo->delete_photo($_GET["photo_id"]);
	} else if ($_GET["profpic"] == 1){
		$ph = new photo_uploader();
		$ph->set_profpic_id($_SESSION["Username"],$photo_id);
		$pf = new profile_handler();
		$pf->retr_details($u,5);
		$ph = new photo_handler();
		$ph->get_url($pf->result[3][0]);
		$prof_pic_user = $ph->result[0];
		
		
		$usrphoto_handler = new photo_handler();
		$usrphoto_handler->view_photo($photo_id);
		if (count($usrphoto_handler->result[3])<7)
				$mulai_tampil = 0;
		else {
			$mulai_tampil = count($usrphoto_handler->result[3])-2;
			?>
			<div id="less_comment_photo"><a id="link_name" href="javascript:viewAllComment('<?php echo $photo_id;?>');">View All Comments(<?php echo $mulai_tampil;?>)</a></div>
			<?php
		}
			?>
			<div id="comment_content_photo">
			<?php
		if ($usrphoto_handler->result[3][0]!=NULL) { 
			for ($k=$mulai_tampil;$k<count($usrphoto_handler->result[3]);$k++) {
				$commentator_details = new profile_handler();
				$commentator_details->retr_details($usrphoto_handler->result[3][$k],5);
				$commentator_photo = new photo_handler();
				$commentator_photo->get_url($commentator_details->result[3][0]);
				?>
				<div id="photo_comment_content<?php echo $usrphoto_handler->result[5][$k];?>">
				<?php 
				$valid = false;
				if ($_SESSION['Username']==$usrphoto_handler->result[3][$k] || $_SESSION['Username']==$usrphoto_handler->result[1])  
					$valid = true;
				if ($valid)
				{
					?>
				<div id="commentphoto_delete"><a href="javascript:deleteComment('<?php echo $usrphoto_handler->result[5][$k];?>','<?php echo $photo_id;?>');">x</a></div>
				<?php
				}
				?>
				<img id="image_commentator_photo" src="<?php echo $commentator_photo->result[0]; ?>" alt="" />
				<div id="name_commentator_photo"><a id="link_name" href="otherprofile.php?id=<?php echo $usrphoto_handler->result[3][$k]; ?>">
				<?php
					echo $commentator_details->result[4][0];
				?>
				</a>
				</div>
				<div id="commentphoto_content">
				<?php
				// echo comment body
				echo $usrphoto_handler->result[4][$k];
				?>
				</div>
				</div>
				<?php
			}
		}
		?>
		</div>
		<?php
		$comment_handler = new photo_handler();
		$comment_handler->retr_photo_details($photo_id,7);
		if ($usr_tag!=null && $comment_handler->result[0]==0) {
			$noshow_comment = false;
		} else if ($user_view!=null && $comment_handler->result[0]==0) {
			$noshow_comment = false;
		} else if (isset($_SESSION['Username']))
			$noshow_comment = true;
		if ($noshow_comment) {
		?>                
		<div id="insert_comment_photo">
			<?php
			if ($user_view==null) {
			?>
			<img id="profpic_small" src="<? echo $prof_pic_user;?>" alt="" style="float:left;" />
			<?php
			} else {
			?>		
			<img id="profpic_small" src="<? echo $prof_pic_user_view;?>" alt="" style="float:left;" />
			<?php
			}
				?>
				<form method="post" action="javascript:submitComment('<?php echo $photo_id;?>', text_comment_photo.value);">
				<div id="insert_comment2">
					<textarea class="textarea" id="text_comment_photo" name="text_comment_photo" size="50px" rows="2" onFocus="if (this.value=='Add a comment') { this.value = '';}" onBlur="if (this.value=='') { this.value = 'Add a comment';}" >Add a comment</textarea>
					<input type="submit" name="SubmitComment" id="SubmitComment2" value="Submit"/>
				</div>
			</form>
            <?php 
			}
        } else if (isset($_GET['changepagephoto'])) {
			$defaultphoto_perpage = $_GET['default'];
			$page_request = $_GET['changepagephoto'];
			$usrphoto_handler = new photo_handler();
			if ($user_view==null && isset($_SESSION['Username'])) {
				$usrphoto_handler->view_all_user_photos($u);
			} else {
				// cari hubungan antara $user_view(yang lagi liatt) dengan $u (yang fotonya diliat)
				$temp_phandler = new follower_handler();
				if ($_SESSION['Username']==null) {
					$hubungan = "everyone";
				} else if ($temp_phandler->is_follow($user_view,$u)) {
					$hubungan = "just followers";
				} else {
					$hubungan = "members only";	
				}
				$usrphoto_handler->view_user_photos_category($u,$hubungan);
			}
			if ($usrphoto_handler->result[0][0]!=NULL) {
					$this_page = $page_request;
					?>
					<div id="page_photo">
					<?php
					for ($page_photo=1;$page_photo<count($usrphoto_handler->result[0])/$defaultphoto_perpage+1;$page_photo++) {
					   if (isset($_GET['UserTujuan']) && $_GET['UserTujuan']!='undefined') {
						   if ($page_photo!=$this_page) {
					?>
						<a href="javascript:change_page_photo('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>','<?php echo $_GET['UserTujuan'];?>');"><?php echo $page_photo;?></a>
					<?php
						   } else {
							 echo $page_photo;  
							}
					   } else {
						   if ($page_photo!=$this_page) {								   
					?>
						<a href="javascript:change_page_photo('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>');"><?php echo $page_photo;?></a>
					<?php								 
						   } else {
							 echo $page_photo;  									   
						   }
					   }
					}
					?>
					</div>                            
				<div id="image_container">
					<ul class="hoverbox"> <?php
				$awal=($page_request-1)*$defaultphoto_perpage;
				$akhir=$awal+$defaultphoto_perpage;
				if($akhir>=count($usrphoto_handler->result[0]))
				{
					$akhir=count($usrphoto_handler->result[0]);
				}
				for($i=$awal;$i<$akhir;$i++) {
					if ($user_view==null && isset($_SESSION['Username'])) {
					?>
					<li>
					<a href="gallery.php?view=2&photo_id=<?php echo $usrphoto_handler->result[0][$i]; ?>"><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" class="preview" /></a>
					</li>	
					<?php
					} else {
						?>
					<li>
					<a href="gallery.php?view=2&photo_id=<?php echo $usrphoto_handler->result[0][$i]; ?>&UserTujuan=<?php echo $u;?>"><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" class="preview" /></a>
                    </li>
					<?php
					}
				}
				?></ul></div><?php
			} else {
				echo "You have not uploaded a photo.";	
			}
		} else if (isset($_GET['changepagephototag'])) {
			$defaultphoto_perpage = $_GET['default'];
			$page_request = $_GET['changepagephototag'];
			$usrtagphoto = new photo_handler();
			if ($user_view==null && isset($_SESSION['Username'])) {
				$usrtagphoto->retr_tagged_photo($u);
			} else {
				// user lain yang liat
				if (isset($_SESSION['Username'])) {
					// member
					$usrtagphoto->view_usertag_photos_category($u,$user_view);
				} else {
					// bukan member
					$usrtagphoto->view_usertag_photos_category($u,"everyone");
				}
			}
			if ($usrtagphoto->result[0]!=null) {
					$akhir = $defaultphoto_perpage;
					$this_page = $page_request;
					?>
					<div id="page_photo">
					<?php
					for ($page_photo=1;$page_photo<count($usrtagphoto->result[0])/$defaultphoto_perpage+1;$page_photo++) {
					   if (isset($_GET['UserTujuan']) && $_GET['UserTujuan']!='undefined') {
						   if ($page_photo!=$this_page) {
					?>
						<a href="javascript:change_page_phototag('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>','<?php echo $_GET['UserTujuan'];?>');"><?php echo $page_photo;?></a>
					<?php
						   } else {
							 echo $page_photo;  
							}
					   } else {
						   if ($page_photo!=$this_page) {								   
					?>
						<a href="javascript:change_page_phototag('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>');"><?php echo $page_photo;?></a>
					<?php								 
						   } else {
							 echo $page_photo;  									   
						   }
					   }
					}
					?>
					</div>                            
					<div id="image_container">
				<ul class="hoverbox"> <?php
				$awal=($page_request-1)*$defaultphoto_perpage;
				$akhir=$awal+$defaultphoto_perpage;
				if($akhir>=count($usrtagphoto->result[0]))
				{
					$akhir=count($usrtagphoto->result[0]);
				}
				for($i=$awal;$i<$akhir;$i++) {
					if ($user_view==null && isset($_SESSION['Username'])) {
					?>
					<li>
					<a href="gallery.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrtagphoto->result[0][$i]; ?>"><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" class="preview" /></a>
					</li>	
					<?php
					} else {
					?>
					<li>
					<a href="gallery.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrtagphoto->result[0][$i]; ?>&UserTujuan=<?php echo $u;?>"><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" class="preview" /></a>
					</li>
					<?php	
					}
				}
				?></ul><?php
			} else {
					echo "No tagged photos.";
			}
		} else if (isset($_GET['sumphotoschange'])) {	
			$defaultphoto_perpage=$_GET['sumphotoschange'];
			$usrphoto_handler = new photo_handler();
			if ($user_view==null && isset($_SESSION['Username'])) {
				$usrphoto_handler->view_all_user_photos($u);
			} else {
				// cari hubungan antara $user_view(yang lagi liatt) dengan $u (yang fotonya diliat)
				$temp_phandler = new follower_handler();
				if ($_SESSION['Username']==null) {
					$hubungan = "everyone";
				} else if ($temp_phandler->is_follow($user_view,$u)) {
					$hubungan = "just followers";
				} else {
					$hubungan = "members only";	
				}
				$usrphoto_handler->view_user_photos_category($u,$hubungan);
			}
			if ($usrphoto_handler->result[0][0]!=NULL) {
				if (count($usrphoto_handler->result[0])>$defaultphoto_perpage) {
					$akhir = $defaultphoto_perpage;
					$this_page = 1;
					?>
					<div id="page_photo">
					<?php
					for ($page_photo=1;$page_photo<count($usrphoto_handler->result[0])/$defaultphoto_perpage+1;$page_photo++) {
					   if (isset($_GET['UserTujuan']) && $_GET['UserTujuan']!='undefined') {
						   if ($page_photo!=$this_page) {
					?>
						<a href="javascript:change_page_photo('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>','<?php echo $_GET['UserTujuan'];?>');"><?php echo $page_photo;?></a>
					<?php
						   } else {
							 echo $page_photo;  
							}
					   } else {
						   if ($page_photo!=$this_page) {								   
					?>
						<a href="javascript:change_page_photo('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>');"><?php echo $page_photo;?></a>
					<?php								 
						   } else {
							 echo $page_photo;  									   
						   }
					   }
					}
					?>
					</div>                            
					<?php
				} else {
					$akhir = count($usrphoto_handler->result[0]);
				}
				?> 
				<div id="image_container">
					<ul class="hoverbox"> <?php
				for($i=0;$i<$akhir;$i++) {
					if ($user_view==null && isset($_SESSION['Username'])) {
					?>
					<li>
					<a href="gallery.php?view=2&photo_id=<?php echo $usrphoto_handler->result[0][$i]; ?>"><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" class="preview" /></a>
					</li>	
					<?php
					} else {
						?>
					<li>
					<a href="gallery.php?view=2&photo_id=<?php echo $usrphoto_handler->result[0][$i]; ?>&UserTujuan=<?php echo $u;?>"><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrphoto_handler->result[1][$i]; ?>" alt="description" class="preview" /></a></li>
					<?php
					}
				}
				?></ul></div><?php
			} else {
				echo "You have not uploaded a photo.";	
			}
			
			?>/*tagtag*/<?php
			$usrtagphoto = new photo_handler();
			if ($user_view==null && isset($_SESSION['Username'])) {
				$usrtagphoto->retr_tagged_photo($u);
			} else {
				// user lain yang liat
				if (isset($_SESSION['Username'])) {
					// member
					$usrtagphoto->view_usertag_photos_category($u,$user_view);
				} else {
					// bukan member
					$usrtagphoto->view_usertag_photos_category($u,"everyone");
				}
			}
			if ($usrtagphoto->result[0]!=null) {
				if (count($usrtagphoto->result[0])>$defaultphoto_perpage) {
					$akhir = $defaultphoto_perpage;
					$this_page = 1;
					?>
					<div id="page_photo">
					<?php
					for ($page_photo=1;$page_photo<count($usrtagphoto->result[0])/$defaultphoto_perpage+1;$page_photo++) {
					   if (isset($_GET['UserTujuan']) && $_GET['UserTujuan']!='undefined') {
						   if ($page_photo!=$this_page) {
					?>
						<a href="javascript:change_page_phototag('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>','<?php echo $_GET['UserTujuan'];?>');"><?php echo $page_photo;?></a>
					<?php
						   } else {
							 echo $page_photo;  
							}
					   } else {
						   if ($page_photo!=$this_page) {								   
					?>
						<a href="javascript:change_page_phototag('<?php echo $page_photo;?>','<?php echo $defaultphoto_perpage;?>');"><?php echo $page_photo;?></a>
					<?php								 
						   } else {
							 echo $page_photo;  									   
						   }
					   }
					}
					?>
					</div>                            
					<?php
				} else {
					$akhir = count($usrtagphoto->result[0]);
				}						
				?> <div id="image_container">
				<ul class="hoverbox"> <?php
				for($i=0;$i<$akhir;$i++) {
					if ($user_view==null && isset($_SESSION['Username'])) {
					?>
					<li>
					<a href="gallery.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrtagphoto->result[0][$i]; ?>"><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" class="preview" /></a>
					</li>	
					<?php
					} else {
					?>
					<li>
					<a href="gallery.php?view=2&usr_tag=<?php echo $u;?>&photo_id=<?php echo $usrtagphoto->result[0][$i]; ?>&UserTujuan=<?php echo $u;?>"><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" /><img src="<?php echo $usrtagphoto->result[1][$i]; ?>" alt="description" class="preview" /></a>
					</li>
					<?php	
					}
				}
				?></ul><?php
			} else {
				echo "No tagged photos.";
			}
		}
?>